var ws = new WebSocket("ws://127.0.0.1:8089/");

ws.onopen = function() {
    console.log("Opened");
};

ws.onmessage = function (evt) {
    console.log(evt.data);
};

ws.onclose = function (err, data) {
    console.log(err);
    console.log(data);
    console.log("Closed");
};

ws.onerror = function(err) {
    console.log("Error: " + err);
};

$(document).ready(function(){
    $('#send').on('click',function(){
        console.log("send");
        ws.send("I'm client1");
    });
    $('#close').on('click',function() {
        ws.onconnecting = function (e) {
            // console.log(e);
            // 因为没有权限, websocket即将关闭
            if (e.code == 4001) {
                // alert(e.reason);
                console.log("4001");
            }
        };
    });
});



